package yxy.apple.protobuf.utility;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import org.junit.Test;

import com.google.protobuf.ByteString;

import yxy.apple.protobuf.Message;
import yxy.apple.util.http.HTTPProtocol;

public class test {
	@Test
	public void test() {
		Message.Parcal.Builder parcal = Message.Parcal.newBuilder();
		parcal.setVersion(0x40000000);
		parcal.setSequence(1);
		parcal.setProto(0x00000008);
		parcal.setData(ByteString.copyFrom(new byte[0]));
		byte[] b = parcal.build().toByteArray();

		try {
			HttpURLConnection connection = null;
			InputStream is = null;
			OutputStream os = null;
			BufferedReader br = null;
			String result = null;
			URL url = new URL("http://192.168.9.33:9999/interact");
			connection = (HttpURLConnection) url.openConnection();
			connection.setRequestMethod("POST");
			connection.setDoOutput(true);
			connection.setRequestProperty("Content-Type", HTTPProtocol.MimeType.ProtoBuf);
			os = connection.getOutputStream();
			os.write(b);
			System.out.println(connection.getResponseCode());
		} catch (Exception e) {
		}
	}

}
